package com.abou.manager.admin.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.abou.manager.admin.IAccountManager;
import com.abou.manager.admin.ILoginManager;
import com.abou.model.admin.Account;

/**
 * The implementation class of the login manager.
 * 
 * @author khalid
 */
@Transactional(readOnly = true)
public class LoginManagerImpl implements ILoginManager {
  
  @Autowired
  private IAccountManager accountManager;
  
  /**
   * @see com.abou.manager.admin.ILoginManager#authenticate(java.lang.String,
   *      java.lang.String)
   */
  public boolean authenticate(String login, String password) {

    boolean authenticated = false;
    
    // getting the account corresponding to the passed credentials
    Account account = accountManager.getAccount(login);
    
    if (account != null) {
      
      authenticated = account.getPassword().equals(password);
    }
    
    return authenticated;
  }
}